package top.chendawei;

import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import top.chendawei.aop.auth.AuthorizeInterceptor;

@Configuration
public class AuthConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authenticationInterceptor())
                .excludePathPatterns("/sso.html","/index.html", "/css/**", "/static/**", "/favicon.ico", "/swagger-resources/**", "/", "***/error", "/error", "/csrf",
                        "/v2/**", "/swagger-ui.html", "/webjars/**")
                .addPathPatterns("/**");
    }

    @Bean
    public AuthorizeInterceptor authenticationInterceptor() {
        return new AuthorizeInterceptor();
    }

    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplateBuilder().build();
    }
}
